package com.demo.rydemo.result;

import lombok.Builder;
import lombok.Data;
import lombok.ToString;

/**
 * @Author ry
 * @Description 统一的前端返回结果
 * @Date 2020/8/3 12:10
 */
@Data
@Builder
@ToString
public class AjaxResult<T> {

    public AjaxResult(Integer code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    Integer code;

    String msg;

    T data;

    public static final int SUCCESS = 200;

    public static final String SUCCESS_MSG = "操作成功";

    public static final int ERROR = 500;

    public static final String ERROR_MSG = "操作失败联系管理员";
    /**
     * 成功返回结果 
     * @param t
     * @return
     */
    public AjaxResult success(T t){
        return AjaxResult.builder().code(SUCCESS).msg(SUCCESS_MSG).data(t).build();
    }


    /**
     * 失败返回结果
     * 1、是否记录错误日志，并保存数据
     * @param msg
     * @return
     */
    public AjaxResult error(String msg){
        return AjaxResult.builder().code(ERROR).msg(ERROR_MSG).build();
    }



}
